package org.cancer.dao

import org.cancer.util.JDBCUtil_Faye
import java.sql.Connection

class CancerTypeDeathDao {

  def updateOrInsertDeathCount(cancerType: String, deathCount: Int): Unit = {
    var connection: Connection = null
    try {
      connection = JDBCUtil_Faye.getConnection
      val sql =
        """
        INSERT INTO cancer_type_death_faye (cancer_type, death_count)
        VALUES (?, ?)
        ON DUPLICATE KEY UPDATE death_count = death_count + ?
        """
      val params = Array(cancerType, deathCount, deathCount)
      JDBCUtil_Faye.executeUpdate(connection, sql, params)
    } catch {
      case e: Exception => e.printStackTrace()
    } finally {
      if (connection != null) connection.close()
    }
  }
}